package com.example.demo.custom;

public class CustomResponse<T> {
    private int code;
    private String message;
    private Boolean success;
    private T data;

    // 无参构造函数
    public CustomResponse() {
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    // 有参构造函数
    public CustomResponse(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.success = true;
        this.data = data;
    }

    public CustomResponse(String message, T data) {
        this.code = 200;
        this.message = message;
        this.success = true;
        this.data = data;
    }

    public CustomResponse(String message) {
        this.code = 200;
        this.message = message;
        this.success = true;
        this.data = null;
    }

    // Getter 和 Setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public CustomResponse<T> success(){
        this.code = 200;
        this.message = "success";
        this.success = true;
        this.data = null;
        return this;
    }

    public CustomResponse<T> error(){
        this.code = 200;
        this.message = "error";
        this.success = false;
        this.data = null;
        return this;
    }
}
